package
{
	import com.wp.datacontainer.map.HashMap;
	
	import data.WalkData;
	import data.db.MapDB;
	
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;

	/**
	 * 地图全局数据、
	 * wuxi create on 2012-9-11 11:18:41
	 * */
	public class MapData
	{
		public function MapData()
		{
		}
		
		
		public static var exportPath:String;
		
		/** 地图列表 */
		public static var db_maps:HashMap = new HashMap();
		/** npc列表 **/
		public static var db_npcs:HashMap = new HashMap();
		/** 怪物列表 **/
		public static var db_monsters:HashMap = new HashMap();
		/**
		 * 正在编辑的地图数据信息
		 * */
		public static var editMap:MapDB;
		
		public static var mapWidth:int = 0;
		
		public static var mapHeight:int = 0;
		
		public static var mapGridSize:int = 25;
		/* 地图名 */
		public static var mapName:String;
		
		public static var zoom:Number = 1;
		
		
		/*** 行走区域信息 * */
		public static var walkX:int = 0;
		public static var walkY:int = 0;
		public static var walkWidth:int = 0;
		public static var walkHeight:int = 0;
		
		/**遮挡点信息*/
		public static var walkArr:HashMap = new HashMap();
		
		[Bindable]
		public static var mapLayers:ArrayCollection = new ArrayCollection();
		
		/** ///////////////   玩家出生点、传送点、npc、怪物的坐标是针对于整个地图的坐标。  在导出地图数据时转化为针对于可行走区域的坐标!!!!    ///////////////////////***/
		
		public static var bornX:int = 1;
		public static var bornY:int = 1;
		
		[Bindable]
		public static var grounds:ArrayCollection = new ArrayCollection();
		[Bindable]
		public static var npcs:ArrayCollection = new ArrayCollection();
		[Bindable]
		public static var monsters:ArrayCollection = new ArrayCollection();
		[Bindabel]
		public static var areas:ArrayCollection = new ArrayCollection();
		/**
		 * 场景中的特效
		 * */
		[Bindable]
		public static var effects:ArrayCollection = new ArrayCollection();
		// ----------------------------------------------  工具处理信息 -----------------------------------------------------------
		public static var map:UIComponent;
		/**
		 * 在地图内,并没有在可行走区域内
		 * */
		public static const INMAP:int = 0;
		/**
		 * 在行走区域内
		 * */
		public static const INWALKAREA:int = 1;
		/**
		 * 点击其他区域
		 * */
		public static const INOTHER:int = 2;
		/**
		 * 检测当前是否点击到了地图区域
		 * */
		public static function getClickInMapArea(mouseX:int,mouseY:int):int{
			if(!map){
				return INOTHER;
			}
			
			//trace(MapData.map.stage.stageWidth + ' ' + MapData.map.stage.stageHeight);
			
			if((mouseX > 0 && mouseX < MapData.map.stage.stageWidth) && (mouseY > 0 && mouseY < MapData.map.stage.stageHeight)){
				// 检测是否在地图区域
				if((mouseX >= map.x && mouseX <= (map.x + mapWidth * zoom)) && 
					                   (mouseY >= map.y && mouseY <= (map.y + mapHeight * zoom))){
					// 检测是否在可行走区域内
					if((mouseX >= (map.x + walkX * zoom) && mouseX <= (map.x + walkX * zoom + walkWidth * zoom)) && 
						                          (mouseY >= (map.y + walkY * zoom) && mouseY <= (map.y + walkY * zoom + walkHeight * zoom))){
						return INWALKAREA; 
					}
					return INMAP;
				}
			}
			
			return INOTHER;
		}
		
		public static function clear():void{
			MapData.exportPath = "";
			MapData.mapWidth = 0;
			MapData.mapHeight = 0;
			MapData.mapGridSize = 0;
			
			MapData.walkWidth = 0;
			MapData.walkHeight = 0;
			MapData.walkX = 0;
			MapData.walkY = 0;
			MapData.bornX = 0;
			MapData.bornY = 0;
			
			MapData.mapLayers.removeAll();
			MapData.grounds.removeAll();
			MapData.npcs.removeAll();
			MapData.monsters.removeAll();
			
			MapData.mapLayers.refresh();
			MapData.grounds.refresh();
			MapData.npcs.refresh();
			MapData.monsters.refresh();
		}
	}
}